# apparently python 2.x is used

"""
I / O   H   S
H       0   -3 
S       1   -2

- keep track of m? doesn't seem worth it to sacrifice oneself for the tribe --> no special action based on m

- first round has enough food to go hunting with everyone <-- 300 * (P - 1)

- count how often it is possible to hunt
-- sort players by reputation (if not enough food to hunt with all players, then prefer players with good reputation)

APPROACH: use "conformity" strategy, differences to myself will be punished

0. first round hunt with everyone

1. filter
--> only hunt with players whose reputation is >= to myself (punishes slackers, but they are able to redeem themselves by hunting again - version of forgiving tit for tat)
--> keep track of how often I'm able to hunt and only look at players with best reputation

2. decide
- punish difference to myself in order to exploit pushovers 
--> difference between other_rep and my_rep (difference is at least 0 because of 1.) is probability of slacking

"""

import random

def hunt_choices(round_number, current_food, current_reputation, m, player_reputations):
    # 0. first round hunt with everyone
    if round_number == 1: return ['h' for x in player_reputations]

    # when only two players are left, slacking becomes dominant 
    if len(player_reputations) == 1: return ['s' for x in player_reputations] 

    max_hunt_count = current_food // 3
    # already low on food --> slack and hope for the best
    if max_hunt_count < 1: return ['s' for x in player_reputations] 

    # after first round
    # 1. filter all players with smaller reputation than myself (mark as 's')
    decisions = {}
    hunt_reps = {}
    hunt_count = 0

    for i, rep in enumerate(player_reputations):
        if rep < current_reputation:
            decisions[i] = 's'
        else:
            # 2. punish difference in order to exploit pushovers
            diff_rep = rep - current_reputation
            rand = random.uniform(0, 1)
            if rand <= diff_rep:
                decisions[i] = 's'
            else:

                if hunt_count < max_hunt_count:
                    decisions[i] = 'h'
                    hunt_count += 1
                    hunt_reps[rep] = i
                
                else:
                    print hunt_count, max_hunt_count
                    # can't hunt with all players -> only look at players with highest reputations
                    min_hunt_rep = min(hunt_reps)
                    if min_hunt_rep >= rep:
                        decisions[i] = 's'
                    else:
                        min_hunt_i = hunt_reps[min_hunt_rep]
                        decisions[min_hunt_i] = 's'
                        decisions[i] = 'h'
                        hunt_reps.pop(min_hunt_rep)
                        hunt_reps[rep] = i

    hunt_decisions = [decisions[i] for i in range(0, len(decisions))]
    return hunt_decisions

def hunt_outcomes(food_earnings):
    pass # do nothing

def round_end(award, m, number_hunters):
    pass # do nothing